<template>
  <div class="content-box-title">
    <div class="content-box-title__content" :style="contentStyle">
      <div class="content-box-title__content__left"></div>
      <div class="content-box-title__content__body">
        <img :src="icon" />
        <div class="content-box-title__content__body__text">{{ title }}</div>
        <img :src="icon" class="flip" />
      </div>
      <div class="content-box-title__content__right"></div>
    </div>
  </div>
</template>

<script>
/**
 * ## ContentBoxTitle
 * 盒子组件的标题组件
 * 用来包装标题中的背景图
 */
import Icon from '@/assets/box-title-left.png'
export default {
  name: 'ContentBoxTitle',
  props: {
    title: {
      type: String,
      default: ''
    },
    width: {
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      icon: Icon
    }
  },
  computed: {
    contentStyle () {
      if (this.width) {
        return { width: this.width + 'px' }
      }
      return {};
    }
  }
}
</script>

<style lang="scss">
.content-box-title {
  color: $box_c;
  font-size: $base * 20px;
  font-family: PingFang-SC-Bold;
  // font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  height: $base * 45px;
  margin-top: $base * -3px;
  .content-box-title__content {
    display: flex;
    .content-box-title__content__left {
      width: 0;
      height: 0;
      border-top: $base * 40px solid $box_bg;
      border-left: $base * 40px solid transparent;
    }
    .content-box-title__content__right {
      width: 0;
      height: 0;
      border-top: $base * 40px solid $box_bg;
      border-right: $base * 40px solid transparent;
    }
    .content-box-title__content__body {
      background: $box_bg;
      font-size: $base * 18px;
      display: flex;
      justify-content: center;
      align-items: center;
      flex: 1;
      img {
        width: $base * 34px;
        height: $base * 16px;
        margin-top: $base * 2px;
      }
      .flip {
        transform: scaleX(-1);
      }
      .content-box-title__content__body__text {
        // padding: 0 15px;
        // min-width: 144px;
        box-sizing: border-box;
        flex: 1;
      }
    }
  }
}
</style>